<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
class Search_model extends CI_Model{
    public function __construct() {
        parent::__construct();
        $this->load->database();
    }
    public function searchResult($Lab_ID/*$keyword*/)
    {
       
        if($Lab_ID==2000)
        {
            $query=$this->db->get('Staff');
            return $query;
        }
        else
        {
        $sql="select * from Staff,LabStaff where Lab_ID='$Lab_ID' and Staff.Staff_ID=LabStaff.Staff_ID";
        $query=$this->db->query($sql);
        return $query;
        }
       
    }
    public function searchResultLimited($Lab_ID,$per_page,$start_row)
    {
        //$tables=array('LabStaff','Staff');
        if($Lab_ID==2000)
        {
            $query=$this->db->get('Staff',$per_page,$start_row);
            return $query;
        }
        else
        {
        $this->db->select('A.Staff_ID,A.FullName,A.FirstName,A.LastName');
        $this->db->from('Staff A');
        $this->db->join('LabStaff B','A.Staff_ID=B.Staff_ID');
        $this->db->where('B.Lab_ID',$Lab_ID);
        $this->db->limit($per_page,$start_row);
        $query=$this->db->get();
        return $query;
        }
        
    }
    public function searchByKeyword($keyword)
    {
        $where="(Staff_ID='$keyword' OR substr(Staff_ID,1,4)='$keyword' OR substr(Staff_ID,1,6)='$keyword' OR substr(Staff_ID,1,8)='$keyword' OR FullName like N'%$keyword%' OR FirstName like N'%$keyword%' OR LastName like N'%$keyword%')";
        $this->db->where($where);
        //$this->db->limit($per_page,$start_row);
        $query=$this->db->get('Staff');
        return $query;
    }
    public function searchByKeywordLimited($keyword,$per_page,$start_row)
    {
        $where="(Staff_ID='$keyword' OR substr(Staff_ID,1,4)='$keyword' OR substr(Staff_ID,1,6)='$keyword' OR substr(Staff_ID,1,8)='$keyword' OR FullName like N'%$keyword%' OR FirstName like N'%$keyword%' OR LastName like N'%$keyword%')";
        $this->db->where($where);
        $this->db->limit($per_page,$start_row);
        $query=$this->db->get('Staff');
        return $query;
    }
}
?>
